package czy.demo.controller.keyword;


import czy.demo.pojo.Person;
import czy.demo.repository.PersonRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/keyword")
@Api(tags = "关键字查询测试")
public class KeywordController {

    @Autowired
    private PersonRepository personRepository;

    @GetMapping("findById")
    @ApiOperation("find关键字")
    public Person findById(Integer id){
        return this.personRepository.findById(id).get();
    }

    @GetMapping("getById")
    @ApiOperation("get关键字")
    public Person getById(Integer id){
        return this.personRepository.getById(id);
    }

    @GetMapping("queryById")
    @ApiOperation("query关键字")
    public Person queryById(Integer id){
        return this.personRepository.queryById(id);
    }

    @GetMapping("findAll")
    @ApiOperation("findAll关键字")
    public List<Person> findAll(){
        return this.personRepository.findAll();
    }

    @GetMapping("findByIdAndName")
    @ApiOperation("And关键字")
    public Person findByIdAndName(Integer id,String name){return this.personRepository.findByIdAndName(id,name);}

    @GetMapping("findByIdOrName")
    @ApiOperation("Or关键字")
    public Person findByIdOrName(Integer id,String name){return this.personRepository.findByIdOrName(id,name);}

    @GetMapping("findByBirthdayBefore")
    @ApiOperation("Before关键字，对应小于条件")
    public List<Person> findByBirthdayBefore(Date end){
        return this.personRepository.findByBirthdayBefore(end);
    }

    @GetMapping("findByBirthdayAfter")
    @ApiOperation("After关键字，对应大于条件")
    public List<Person> findByBirthdayAfter(Date start){
        return this.personRepository.findByBirthdayAfter(start);
    }

    @GetMapping("findByBirthdayBetween")
    @ApiOperation("Between关键字，对应between ? and ?条件")
    public List<Person> findByBirthdayBetween(Date start,Date end){
        return this.personRepository.findByBirthdayBetween(start,end);
    }

    @GetMapping("findByBirthdayIsBefore")
    @ApiOperation("IsBefore关键字，对应小于条件")
    public List<Person> findByBirthdayIsBefore(Date end){
        return this.personRepository.findByBirthdayIsBefore(end);
    }

    @GetMapping("findByBirthdayIsAfter")
    @ApiOperation("IsAfter关键字，对应大于条件")
    public List<Person> findByBirthdayIsAfter(Date start){
        return this.personRepository.findByBirthdayIsAfter(start);
    }

    @GetMapping("findByBirthdayIsBetween")
    @ApiOperation("IsBetween关键字，对应between ? and ?条件")
    public List<Person> findByBirthdayIsBetween(Date start,Date end){
        return this.personRepository.findByBirthdayIsBetween(start,end);
    }

}
